package com.xquant.marketdata.marketdata.controller;

import com.xquant.marketdata.utils.CommResponse;
import com.xquant.marketdata.utils.SysUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.UnsupportedEncodingException;

/**
 * 下拉框查询
 *
 * @author ershuai.zhao
 */
@RestController
@RequestMapping("fileController")
public class FileController {

    /**
     * 查询
     */
    @ResponseBody
    @RequestMapping(value = "/fileIsExist.action")
    public Object fileIsExist(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {

        return new CommResponse(true);
    }
    /**
     * 查询
     */
    @ResponseBody
    @RequestMapping(value = "/downloadFile.action")
    public Object downloadFile(HttpServletRequest request,HttpServletResponse response, @RequestParam(value = "fileType") String fileType,
                               @RequestParam(value = "fileName") String fileName)   {
       try {
           //为文件名解码
           fileName = SysUtils.decode(fileName);
           fileName = fileName.replace("%20", " ");
           fileName = "110.xls";
           String path = SysUtils.getSysPath01()+"templates";

           String fullFilePath = path + File.separator + fileName;

           response = SysUtils.downloadFile(response, fullFilePath, fileName);
       }catch (Exception e){
            e.getMessage();
       }
        return new CommResponse(true);
    }


}
